from pyspark import SparkConf, SparkContext
import os

# 设置python解释器环境变量
os.environ['PYSPARK_PYTHON'] = 'D:/PYTHON/python3.10/python.exe'

conf = SparkConf().setMaster('local[*]').setAppName('my_test_spark')
sc = SparkContext(conf=conf)

rdd = sc.parallelize(['happy nice good', 'I love you', 'good morning', 'I will succeed'])
rdd1 = rdd.map(lambda x: x.split(' '))
print(F'map算子：{rdd1.collect()}')

print(F'flatMap算子：{rdd.flatMap(lambda x: x.split(" ")).collect()}')

sc.stop()
